//
//  MyMainView.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/8/29.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "MyMainView.h"


@interface MyMainView ()

@property(nonatomic,strong)UIImageView *iconImageView;
@property(nonatomic,strong)UIImageView *backImage;

@end

@implementation MyMainView

-(instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self initViews];
    }
    return self;
}

-(void)initViews{
    _backImage = [[UIImageView alloc]init];
    if (iPhoneX) {
        _backImage.image = [UIImage imageNamed:@"my_bj_iphoneX"];
    }else {
        _backImage.image = [UIImage imageNamed:@"my_bj"];
    }
    [self addSubview:_backImage];
    [_backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(self);
    }];
    
    _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_pic_defaut"]];
    [self addSubview:_iconImageView];
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(55, 55));
        make.left.mas_equalTo(self.mas_left).offset(ApplicationBackGauge + 8);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-30);
    }];
    
    _telLabel = [[UILabel alloc] init];
    _telLabel.text = @"*** **** ****";
    [self addSubview:_telLabel];
    _telLabel.textColor = [UIColor whiteColor];
    _telLabel.font = [UIFont boldSystemFontOfSize:18];
    [_telLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconImageView.mas_top).offset(2);
        make.left.mas_equalTo(self.iconImageView.mas_right).offset(16);
    }];
    
}

- (void)updateInfoWithGrade:(NSString *)grade {
    
    //authenticationGrade  1 初级 2高级   3审核中
    if ([grade isEqualToString:@"1"]) {
        if (_renZhengEdView) {
            self.renZhengEdView.hidden = YES;
        }
        if (_renZhengIngView) {
            self.renZhengIngView.hidden = YES;
        }
        self.unRenZhengView.hidden = NO;
        [self.unRenZhengView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.iconImageView.mas_bottom).offset(-2);
            make.left.mas_equalTo(self.iconImageView.mas_right).offset(16);
            make.width.mas_equalTo(200);
            make.height.mas_equalTo(20);
        }];
    }else if ([grade isEqualToString:@"3"]) {
        if (_renZhengEdView) {
            self.renZhengEdView.hidden = YES;
        }
        if (_unRenZhengView) {
            self.unRenZhengView.hidden = YES;
        }
        self.renZhengIngView.hidden = NO;
        [self.renZhengIngView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.iconImageView.mas_bottom).offset(-2);
            make.left.mas_equalTo(self.iconImageView.mas_right).offset(16);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(15);
        }];
    }else if ([grade isEqualToString:@"2"]) {
        if (_unRenZhengView) {
            self.unRenZhengView.hidden = YES;
        }
        if (_renZhengIngView) {
            self.renZhengIngView.hidden = YES;
        }
        self.renZhengEdView.hidden = NO;
        [self.renZhengEdView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.iconImageView.mas_bottom).offset(-2);
            make.left.mas_equalTo(self.iconImageView.mas_right).offset(16);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(15);
        }];
    }
    
}

//去实名认证
- (void)goToRenZhengAction {
    
    if ([self.delegate respondsToSelector:@selector(goToGaoJiRenZhengVC)]) {
        [self.delegate goToGaoJiRenZhengVC];
    }
}


- (UIView *)unRenZhengView {
    
    if (!_unRenZhengView) {
        _unRenZhengView = [[UIView alloc] init];
        
        [self addSubview:_unRenZhengView];
        
        UILabel *leftLabel = [[UILabel alloc] init];
        leftLabel.text = @"初级认证";
        leftLabel.textColor = HexColor(0xA6A6A6);
        leftLabel.font = [UIFont systemFontOfSize:12];
        [_unRenZhengView addSubview:leftLabel];
        [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.mas_equalTo(_unRenZhengView);
            make.width.mas_equalTo(50);
        }];
        UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_unRenZhengView addSubview:rightBtn];
        rightBtn.layer.cornerRadius = 10;
        rightBtn.layer.masksToBounds = YES;
        
        [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(103, 20));
            make.left.mas_equalTo(leftLabel.mas_right).offset(10);
            make.centerY.mas_equalTo(leftLabel);
        }];
        
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.colors = @[(__bridge id)HexColor(0xD6C096).CGColor, (__bridge id)HexColor(0xBEA471).CGColor];
        gradientLayer.locations = @[@0, @1];
        gradientLayer.startPoint = CGPointMake(0, 1);
        gradientLayer.endPoint = CGPointMake(1, 1);
        gradientLayer.frame = CGRectMake(0, 0, 103, 20);
        [rightBtn.layer addSublayer:gradientLayer];
        
        UILabel *btnLabel = [[UILabel alloc] init];
        btnLabel.textColor = [UIColor whiteColor];
        btnLabel.text = @"高级实名认证";
        btnLabel.font = [UIFont systemFontOfSize:12];
        [rightBtn addSubview:btnLabel];
        
        [btnLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_equalTo(rightBtn);
            make.left.mas_equalTo(rightBtn.mas_left).mas_equalTo(10);
            make.width.mas_equalTo(74);
        }];
        
        UIImageView *btnImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_gaojirenzheng_right"]];
        [btnImageView setContentMode:UIViewContentModeScaleAspectFit];
        [rightBtn addSubview:btnImageView];
        [btnImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(10, 10));
            make.left.mas_equalTo(btnLabel.mas_right);
            make.centerY.mas_equalTo(rightBtn);
        }];
        
        [rightBtn addTarget:self action:@selector(goToRenZhengAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _unRenZhengView;
}

- (UIView *)renZhengIngView {
    
    if (!_renZhengIngView) {
        _renZhengIngView = [[UIView alloc] init];
        
        [self addSubview:_renZhengIngView];
        
        UILabel *leftLabel = [[UILabel alloc] init];
        leftLabel.text = @"高级实名认证中";
        leftLabel.textColor = HexColor(0xFFD083);
        leftLabel.font = [UIFont systemFontOfSize:12];
        [_renZhengIngView addSubview:leftLabel];
        [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.right.mas_equalTo(_renZhengIngView);
        }];
        
    }
    return _renZhengIngView;
}
- (UIView *)renZhengEdView {
    
    if (!_renZhengEdView) {
        _renZhengEdView = [[UIView alloc] init];
        
        [self addSubview:_renZhengEdView];
        
        UIImageView *leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"v"]];
        [leftImageView setContentMode:UIViewContentModeScaleAspectFit];
        [_renZhengEdView addSubview:leftImageView];
        [leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(10, 10));
            make.left.mas_equalTo(_renZhengEdView.mas_left);
            make.centerY.mas_equalTo(_renZhengEdView);
        }];
        
        UILabel *rightLabel = [[UILabel alloc] init];
        rightLabel.text = @"高级实名认证";
        rightLabel.textColor = HexColor(0xFFD083);
        rightLabel.font = [UIFont systemFontOfSize:12];
        [_renZhengEdView addSubview:rightLabel];
        [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.right.mas_equalTo(_renZhengEdView);
            make.left.mas_equalTo(leftImageView.mas_right).offset(4);
        }];
        
    }
    return _renZhengEdView;
}



@end
